﻿using System;
using System.Windows;
using Baosight.ZNH.ZMCommon;
using Baosight.Platform.Core.UI.Controls;
using Baosight.Platform.Core;
using Baosight.ZNH.ZMCS.UI.Utils;

namespace Baosight.ZNH.ZMCS.UI
{
    /// <summary>
    /// 系统参数设置
    /// </summary>
    /// Title:ZMCS22
    /// Copyright:Baosight Software LTD.co Copyright (c) 2011
    /// Company:上海宝信软件股份有限公司
    /// Author: 张志芳
    /// Version: 1.0
    /// History:
    ///       2010-12-14  张志芳   [创建]
    ///       2011-05-16  严洪浩   [重新修改TABITEM形式和主从形式]
    ///
    public partial class ZMCS11 : EFViewCmes
    {
        public ZMCS11()
        {
            InitializeComponent();
            base.BeforeAction += OnBeforeAction;
        }
        /// <summary>
        /// Load事件中初始化父类EFViewCmesProperty的值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnBeforeAction(object sender, EventArgs e)
        {
            EFViewCmesProperty _view = new EFViewCmesProperty();
            _view.DataFields = this.InsertPanel.GetChildObjects<EFDataField>(null, true);
            _view.ListPageNo = "ZMCS11";
            _view.ViewType = "details";

            _view.Args.Add("fdModuleNo", this.fdModuleNo.GetDataValue().ToString());
            base.ViewProperty = _view;
        }

        public override void Initialize(EIInfo initData)
        {
            SystemSettingBlock _block = new SystemSettingBlock();
            initData.AddBlock(_block.GetEngineeringNo());
            initData.AddBlock(_block.GetMiningType());
            initData.AddBlock(_block.GetSystemModel());

            base.Initialize(initData);
            //判断页面时新增页还是编辑页
            InitDataSet(initData);
        }

        /// <summary>
        /// 给Mode付值
        /// </summary>
        /// <param name="initData"></param>
        private void InitDataSet(EIInfo initData)
        {
            Mode = (OperationMode)Enum.Parse(typeof(OperationMode), "Update", true);
        }

        /// <summary>
        /// 第一个EFRegion修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void OnUpdateButtonClick(object sender, RoutedEventArgs e)
        {
            base.OnSureButtonClick(sender, e);
        }

        /// <summary>
        /// 第二个EFRegion修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void OnModifyButtonClick(object sender, RoutedEventArgs e)
        {
            base.CmesSureRecordBtn("ZMCS11", "updateRuleSet", "result", sender, e);
        }

        #region 页面操作事件
        /// <summary>
        /// 根据fdEngineeringNo的值不同，来确定工程规则是否只读
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdEngineeringNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {

            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdEngineeringNoRule.IsReadOnly = false;
            }
        }

        /// <summary>
        /// 根据fdWorkingfaceNo的值不同，来确定工作面规则是否只读
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdWorkingfaceNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdWorkingfaceNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdWorkingfaceNoRule.IsReadOnly = false;
            }
        }

        /// <summary>
        /// 根据fdRoadwayNo的值不同，来确定巷道规则是否只读
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdRoadwayNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdEngineeringNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdRoadwayNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdRoadwayNoRule.IsReadOnly = false;
            }
        }

        /// <summary>
        /// 根据fdOtherDesignNo的值不同，来确定其他规则是否只读
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdOtherDesignNo_ValueChanged(object sender, ValueChangedEventArgs e)
        {
            string _value = e.NewValue as string;

            if (null == _value)
            {
                //this.fdOtherDesignNoRule.IsReadOnly = true;
            }
            else if (_value == "1")
            {
                this.fdOtherDesignNoRule.IsReadOnly = true;
            }
            else
            {
                this.fdOtherDesignNoRule.IsReadOnly = false;
            }
        }

        /// <summary>
        /// 工作面，初始数据加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdWorkingfaceNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdWorkingfaceNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdWorkingfaceNoRule.IsReadOnly = true;
            }
        }

        /// <summary>
        /// 巷道，初始数据加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdRoadwayNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdRoadwayNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdRoadwayNoRule.IsReadOnly = true;
            }
        }

        /// <summary>
        /// 工程，初始数据加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdEngineeringNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdEngineeringNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdEngineeringNoRule.IsReadOnly = true;
            }
        }

        /// <summary>
        /// 其他，初始数据加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void fdOtherDesignNo_Loaded(object sender, RoutedEventArgs e)
        {
            var _value = this.fdOtherDesignNo.Value;
            if (null != _value && _value.ToString() == "1")
            {
                this.fdOtherDesignNoRule.IsReadOnly = true;
            }
        }
        #endregion
    }
}
